﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;

namespace DAO
{
    public static class TaiKhoanNganLuongDAO
    {
        public static TaiKhoanNganLuongDTO getTaiKhoanNganLuong(string mataikhoan, string matkhau)
        {
            TaiKhoanNganLuongDTO tk = new TaiKhoanNganLuongDTO();
            try
            {
                IList<SqlParameter> arrParameter = new List<SqlParameter>();
                arrParameter.Add(new SqlParameter("@TaiKhoanNganLuong", mataikhoan));
                arrParameter.Add(new SqlParameter("@MatKhau", matkhau));
                DataTable dt = DataProvider.ExecuteStoreProc("getTaiKhoanNganLuong", arrParameter);
                if (dt.Rows.Count > 0)
                {
                    tk.TaiKhoanNganLuong = dt.Rows[0][0].ToString();
                    tk.MatKhau = dt.Rows[0][1].ToString();
                    tk.SoDuTaiKhoan = int.Parse(dt.Rows[0][2].ToString());
                    return tk; ;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Lỗi khi lat tai khoan ngan luong " + ex.ToString());
            }
            return null;
        }

        public static void CapNhat(string mataikhoan, double sotien)
        {
            IList<SqlParameter> arrParameter = new List<SqlParameter>();
            arrParameter.Add(new SqlParameter("@TaiKhoanNganLuong", mataikhoan));
            arrParameter.Add(new SqlParameter("@SoTien", sotien));
            DataProvider.ExecuteStoreProc("updateTaiKhoanNganLuong", arrParameter);
        }
    }
}
